package com.eng.carro.services;

import javax.ejb.Stateless;
import javax.persistence.TypedQuery;

import com.eng.carro.entities.User;

@Stateless
public class UserService extends BaseServiceProvider<User, Integer> {

  public User findByEmailPass(User user) {

	try {
	  TypedQuery<User> query = em.createQuery("SELECT u from "
		  + getPersistentClass().getSimpleName()
		  + " u WHERE u.email = :par1 AND u.password = :par2",
		  getPersistentClass());
	  query.setParameter("par1", user.getEmail());
	  query.setParameter("par2", user.getPassword());

	  User user2 = query.getSingleResult();
	  
	  return user2;
	} catch (Exception e) {
	  // TODO: handle exception
	}
	return null;
  }

}
